package pers.chy.chyappointmentplatform.WS;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

/**
 * 调用集成平台WebSerivce接口
 * 全部写为【静态】
 */
public class WsClient_HIP {
    private static JaxWsDynamicClientFactory factroy = null;
    private static Client client=null;

    /**
     * 单例
     * @return
     */
    private static Client getClient(){
        if(factroy==null){
            factroy = JaxWsDynamicClientFactory.newInstance();
        }
        if(client==null){
            // 集成平台服务地址
            client = factroy.createClient("http://192.0.1.162:9528/hai/WebServiceEntry?wsdl");
        }
        return client;
    }


    /**
     * 调用
     * @param serviceName 服务名
     * @param uid
     * @param pwd
     * @param param 参数（XML格式）
     * @return
     * @throws Exception
     */
    public static String call(String serviceName,String uid,String pwd,String param) throws Exception {
        // 调用
        Object[] results = getClient().invoke(
                "invoke", // 接口函数名
                serviceName,// 参数1
                uid,        // 参数2
                pwd,        // 参数3
                param       // 参数4
        );
        return (String)results[0];
    }
}
